#ifndef RENDERER_H
#define RENDERER_H

#include <sokol_gfx.h>
#include "../pacman/interface.h"

typedef struct GameRenderer {
    sg_shader shader;
    sg_shader display_shader;
    sg_image character_texture;
    sg_image sprite_texture;
    sg_image palette_texture;

    sg_attachments fbo;
    sg_image fbo_color;
    sg_image fbo_depth;

    sg_buffer tile_buffers[3];

    size_t tile_buf_size;
    size_t tile_palette_buf_size;
    float* tile_buf;
    float* tile_palette_buf;
    
    sg_buffer sprite_buffers[3];
    int active_sprite_count;

    sg_buffer display_vbuffers[2];

    size_t sprite_buf_size;
    size_t sprite_palette_buf_size;
    float* sprite_buf;
    float* sprite_palette_buf;

    sg_sampler sampler;
    sg_pipeline game_pip;
    sg_pipeline window_pip;

    int view_width;
    int view_height;

    sg_environment environment;
} GameRenderer;

/// Initialize the OpenGL game renderer.
/// Returns a non-zero value if there was an error.
extern int game_renderer_init(GameRenderer* rndr, GameInterface* interface);

/// Free resources that the game renderer allocated
extern void game_renderer_free(GameRenderer* rndr);

/// Draw the state of a GameInterface
extern void game_renderer_draw(GameRenderer* rndr, DisplayInfo* display_info);

#endif